
import './china.js';
import setting from './setting';
let mapName = 'china';
let geoCoordMap = {};
var mapFeatures = echarts.getMap(mapName).geoJson.features;
mapFeatures.forEach(function (v) {
    // 地区名称
    var name = v.properties.name;
    // 地区经纬度
    geoCoordMap[name] = v.properties.cp;

});

function convertData(data) {
    var res = [];
    for (var i = 0; i < data.length; i++) {
        var geoCoord = geoCoordMap[data[i].name];
        console.log(geoCoord)
        if (geoCoord) {
            res.push({
                name: data[i].name,
                value: geoCoord.concat(data[i].value),
            });
        }
    }
    return res;
};

function getOpt({
    data = [],
    visualMap={}
    //toolTipData
} = {}) {
    let visualMapSet =Object.keys(visualMap).length>0?visualMap:setting.visualMap;
    let option = {
        tooltip: {
            // triggerOn: "click",
            trigger: 'item',
            // formatter: function (e, t, n) {
            //     let splitData = toolTipData.get(e.name).split('-');
            //     let toolTiphtml = '';
            //     toolTiphtml += `${e.name}：<br />确诊人数：${splitData[0]||0}<br />治愈人数：${splitData[1]||0}<br />死亡人数：${splitData[2]||0}`
            //     return toolTiphtml;
            // }
        },
        visualMap: visualMapSet,
        geo: {
            map: mapName,
            roam: false,
            aspectScale: .9,
            scaleLimit: {
                min: 1,
                max: 2
            },
            zoom: 1.1,
            top: 80,
            label: {
                normal: {
                    show: true,
                    fontSize: "16",
                    color: "#fff"
                }
            },
            itemStyle: {
                areaColor: '#0E95F1',
                borderColor: 'rgba(255,255,255,0.6)',
                borderWidth: 1,
                shadowColor: '#0E95F1',
                shadowBlur: 0,
            },
            emphasis: {
                label: {
                    show: true,
                    color: '#fff',
                    fontSize: 18
                },
                itemStyle: {
                    areaColor: '#FFD181',
                    borderColor: '#fff',
                    borderWidth: 1
                }
            },
        },
        series: [
            {
                name: "确诊病例",
                type: "map",
                map: mapName,
                showLegendSymbol: false, // 存在legend时显示
                geoIndex: 0,
                data: data
            }
        ]
    };
    return option;
}

export default getOpt;